package com.healthcloud.tag;

import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;

import com.healthcloud.entity.SysConfigEntity;
import com.healthcloud.service.SysConfigService;
import com.healthcloud.utils.SpringUtil;

/**
 * 下拉枚举选项
 * @author zj
 *
 */
public class ConfigJsonTag extends SimpleTagSupport {

	private String name;
	
    private SysConfigService sysConfigService = (SysConfigService) SpringUtil.getBean("sysConfigService");

	public void setName(String name) {
		this.name = name;
	}

	StringWriter sw = new StringWriter();

	public void doTag() throws JspException, IOException {
		JspWriter out = getJspContext().getOut();
		Map<String, Object> map = new HashMap<String, Object>();
		if (StringUtils.isNotEmpty(name)) {
			List<SysConfigEntity> list = sysConfigService.queryListByName(name);
			if (list!=null&&list.size()>0) {
				for (SysConfigEntity entity : list) {
					map.put(entity.getKey(), entity.getValue());
				}
			}
		}
		out.print(JSONObject.fromObject(map).toString());
	}

}
